const mysqldb = require("../util/db.js")

exports.operation = function (operation, param, cb) {
    var db = new mysqldb.db()
    let sql = ''
    switch (operation) {
        case "select":
            sql = "select * from `base_cmd` where ( CMD like '%" + param.CMD + "%' or '" + param.CMD + "'='') and ( TEXT like '%" + param.TEXT + "%' or '" + param.TEXT + "'='')\
<<<<<<< HEAD
                   and (ID="+ param.ID + " or " + param.ID + "=0 )  AND ISDEL!=1 ORDER BY ID DESC";
=======
                   and (ID="+ param.ID + " or " + param.ID + "=0 ) ORDER BY ID DESC";
>>>>>>> f39b58d3ecd4b966b4fad479559750bf2f0d0858
            break;
        case "update":
            sql = "update `base_cmd` set `CMD`='" + param.CMD + "',`SQL`=\"" + param.SQL + "\",`TEXT`='" + param.TEXT + "' where ID=" + param.ID + "";
            break;
        case "insert":
<<<<<<< HEAD
            sql = "INSERT INTO `base_cmd` ( `CMD`, `SQL`, `TEXT`, `ISDEL`) VALUES ('" + param.CMD + "',\"" + param.SQL + "\",'" + param.TEXT + "',0) ";
            break;
        case "delete":
            sql = "update `base_cmd` set ISDEL=1  where ID=" + param.ID + "";
=======
            sql = "INSERT INTO `base_cmd` ( `CMD`, `SQL`, `TEXT`) VALUES ('" + param.CMD + "',\"" + param.SQL + "\",'" + param.TEXT + "') ";
            break;
        case "delete":
            sql = "delete from `base_cmd` where ID=" + param.ID + " "
>>>>>>> f39b58d3ecd4b966b4fad479559750bf2f0d0858
            break;
    }
    db.getAll(sql, (err, data) => {
        if (err) {
            cb(err)
            console.log('errsql:' + err.sql)
        } else {
            cb(data)
        }
    })
}